package control;

import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.SwingUtilities;

import view.AddFrame;
import view.DelFrame;
import view.LoginPanel;
import view.UpdFrame;

public class ControlMain extends JFrame implements ActionListener {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	public ControlMain() {
		setTitle("学生信息管理");
		setLayout(null);
		setVisible(true);
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		setSize(380, 220);
		setResizable(false);
		Dimension ds = Toolkit.getDefaultToolkit().getScreenSize();
		setLocation((ds.width - 300) / 2, (ds.height - 300) / 2);
		String[] str = { "添加学生信息", "删除学生信息", "修改学生信息", "查询学生信息" };
		JButton[] jbt = new JButton[str.length];
		for (int i = 0; i < str.length; i++) {
			jbt[i] = new JButton(str[i]);
			jbt[i].setSize(120, 30);
			jbt[i].setLocation(20, 20 + i * 40);
			jbt[i].addActionListener(this);
			add(jbt[i]);
		}

		Font font = new Font("微软雅黑", Font.BOLD, 15);
		JLabel dlabel = new JLabel("Driver Loading Success!");
		dlabel.setFont(font);
		dlabel.setBounds(180, 50, 200, 20);
		add(dlabel);
		JLabel clabel = new JLabel("Database Link Success!");
		clabel.setFont(font);
		clabel.setBounds(180, 90, 200, 20);
		add(clabel);
		LoginPanel lp = new LoginPanel();
		// setGlassPane(lp);
		lp.setVisible(true);
	}

	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {

			@Override
			public void run() {
				new ControlMain();

			}
		});
	}

	@Override
	public void actionPerformed(ActionEvent a) {
		// TODO Auto-generated method stub
		String cmd = a.getActionCommand();
		switch (cmd) {
		case "添加学生信息":
			this.setVisible(false);

			new AddFrame();
			break;
		case "删除学生信息":
			this.setVisible(false);
			new DelFrame();
			break;
		case "修改学生信息":
			this.setVisible(false);
			new UpdFrame();
			break;
		}
	}

}
